// const baseUrl = 'http://vend.ztits.cn'
const baseUrl = ''

function ajax(option) {
	const url = option.url;
	if (!option.url) {
		console.log('url是必填项')
		return;
	}
	const data = option.data || {};
	const header = 'application/x-www-form-urlencoded'
	const method = option.method.toUpperCase() || 'GET';
	const dataType = 'json'

	return new Promise((resolve, reject) => {
		console.log(data, '发送前查看数据');
		wx.request({
			url: url,
			data: data,
			header: {
				'content-type': header,
				// 'auth-token': '24d843fc7b0e7e5e178ae397afcc2af6',
				// 'user-id': '3',
				'token': '1111'
			},
			method: method,
			dataType: dataType,
			success(res) {
				resolve(res)
			},
			fail(err) {
				reject(err)
			}
		})
	})


}

module.exports = {
	get(url, data) {
		return ajax({
			url: baseUrl + url,
			method: 'get',
			data: data
		})
	},
	post(url, data) {
		return ajax({
			url: baseUrl + url,
			method: 'post',
			data: data
		})
	}
}